<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box">

    </div>
  
    <script src="./js/react18.js"></script>
    <script src="./js/react-dom18.js"></script>
    <script src="./js/babel.min.js"></script>
    <script src="./js/prop-types.js"> </script>
    
    <script type="text/babel">

        // 创建一个根对象：
        let root = ReactDOM.createRoot(document.getElementById("box"));
        
        function Person(props){
            return (
                <ul>
                    <li>姓名:{props.name}</li>
                    <li>性别:{props.sex}</li>
                    <li>年龄:{props.age}</li>
                </ul>
            )
        }

        // 函数式组件属性的类型验证：
        Person.propTypes = {
            name:PropTypes.string,
            sex:PropTypes.string,
            age:PropTypes.number
        }
       

        class Book extends React.Component{

            static  propTypes = {
                name:PropTypes.string.isRequired,
                author:PropTypes.string,
                price:PropTypes.number
            }
        
            render(){
                return (
                      <ul>
                        <li>书名:{this.props.name}</li>
                        <li>作者:{this.props.author}</li>
                        <li>价格:{this.props.price}</li>
                    </ul>
                )
            }
        }

        // Book.propTypes = {
        //     name:PropTypes.string,
        //     author:PropTypes.string,
        //     price:PropTypes.number
        // }

        const age = 12;

        const jsx =(
            <div>
                 <Person name="刘梁涛"  sex="男" age={18} />
                <Book author="罗贯中" price="12"  /> 
            </div>)


        // 把jsx渲染到根对象对应的dom容器里
        root.render(jsx);
        

    </script>
</body>

</html>